#!/usr/bin/python
#-*-coding: utf-8 -*-

__all__ = [u'GuiToolButton']

from PyQt4 import QtGui

class GuiToolButton (QtGui.QWidgetAction):

  def __init__(self, menu, default_action=None, parent=None):
    self._menu = menu
    self._default_action = default_action
    QtGui.QWidgetAction.__init__ (self, parent)

  def createWidget(self, parent):
    widget = QtGui.QToolButton(parent)
    if isinstance(self._default_action, QtGui.QAction):
      widget.setDefaultAction(self._default_action)
    widget.setMenu(self._menu)
    return widget
